﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPF_DbCenter.CommonMethod;
using Microsoft.Win32;

namespace WPF_DbCenter.SqlCE.AdditionUI
{
    /// <summary>
    /// Interaction logic for Csv2Sdf.xaml
    /// </summary>
    public partial class Csv2Sdf : BaseUI.BaseFadeDialog
    {
        public Csv2Sdf()
        {
            InitializeComponent();
        }

        private void butSync_Click(object sender, RoutedEventArgs e)
        {
            if ((string.IsNullOrEmpty(txtSrcFile.Text)) || (string.IsNullOrEmpty(txtTargetFile.Text)))
            {
                MessageBox.Show("Please select source access file or the target file");
                return;
            }
            string csvFile = txtSrcFile.Text;
            string sdfFile = txtTargetFile.Text;
            try
            {
                if (CommonUtil.ConvertCSVToSdf(csvFile, sdfFile, (bool)checkBox1.IsChecked, txtPwd.Password))
                {
                    MessageBox.Show(String.Format("Sync data from \r\n{0} \r\nto \r\n{1} \r\nSuccessful.", csvFile, sdfFile));
                    Close();
                }
            }
            catch (Exception ee)
            {
                XLCS.Common.ProcessException.DisplayErrors(ee);
            }
        }

        private void butSelectSource_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog sf = new OpenFileDialog();
            sf.Filter = AppEntry.CVS_FILE_FILTER;
            if (sf.ShowDialog() == true)
            {
                this.txtSrcFile.Text = sf.FileName;
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog sf = new OpenFileDialog();
            sf.Filter = AppEntry.SQLCE_FILE_FILTER;
            if (sf.ShowDialog() == true)
            {
                this.txtTargetFile.Text = sf.FileName;
            }
        }
    }
}
